package com.study.designmodes.controller.pattern.strategy.highlevel;

import com.study.designmodes.enums.BusinessCodeEnum;
import com.study.designmodes.enums.InsuranceCategoryEnum;
import com.study.designmodes.request.BusinessCommonParam;
import com.study.designmodes.service.strategy.BusinessTaskHandler;
import com.study.designmodes.service.strategy.component.StrategyAnnotationFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 注解版-策略bean工厂模式
 *
 * @author yangyanbin
 * @since 20221106
 **/
@RestController
@RequestMapping("/high/strategy")
public class StrategyHighController {

    /**
     * @Description: 根据不同的Object对象通过策略bean工厂路由到不同的业务实现
     * @Param: [businessObjectRequest]
     * @return:
     */
    @PostMapping("/strategy")
    public String strategyChoose(@RequestBody BusinessCommonParam param) {
        InsuranceCategoryEnum categoryEnum = InsuranceCategoryEnum.getByCode(param.getCategoryCode());
        BusinessCodeEnum businessCodeEnum = BusinessCodeEnum.getByCode(param.getBusinessCode());
        BusinessTaskHandler businessTaskHandler = StrategyAnnotationFactory.getBusinessTaskV2Handler(categoryEnum, businessCodeEnum);
        businessTaskHandler.handleBusinessTask(param.getTaskNumber());
        return null;
    }

}
